/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tesam.gedeon.dao.impl;

import com.tesam.gedeon.dao.ProvinceDao;
import com.tesam.gedeon.entity.Department;
import com.tesam.gedeon.entity.Province;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Sistema
 */
@Repository
public class ProvinceDaoImpl  extends SimpleJdbcDaoSupport implements ProvinceDao {
    
    @Autowired
    public ProvinceDaoImpl(DataSource dataSource) {
        setDataSource(dataSource);
    }

    @Override
    public List<Province> getListByDepartmentAndCountry(Province province) {
        List<Province> result = new ArrayList();
        try{
          
               result = getJdbcTemplate().query("select id , code_country , code_department , code , name "
                       + "from province where deleted = 0 and upper(code_department) = '"+province.getDepartment().getCode().toUpperCase()+"' "
                       + "and upper(code_country) = '"+province.getCountry().getCode().toUpperCase()+"'" 
                     , new BeanPropertyRowMapper<Province>(Province.class));
        }catch(Exception e){
            System.out.println("getListByDepartmentAndCountry : "+e.getMessage());
        }
        return result ;
    }
    
}
